<?php
/**
 * Created by PhpStorm.
 * User: Season
 * Date: 2018/6/14
 * Time: 22:09
 */

$pattern = '/\{#';
$pattern .= ' *\$([a-zA-Z_]\w*) *';
$pattern .= '#\}/';
$sunject = '测试：{#$test#}';
$sunject = preg_replace($pattern,'<?php echo $$1; ?>',$sunject);

echo $sunject;